import { getFileTree } from "@/apis/web/File"
import { useLocalStorage } from "@/hooks/useLocalStorage"
import { RootState } from "@/store"
import { Module } from "vuex"
import { IFileListActions, IFileListGetter, IFileListMutations, IFileListState } from "./types"
const { setLocalStorage, getLocalStorage } = useLocalStorage()
const state: IFileListState = {
    title: '文件列表',
    searchTips: '请输入文件名',
    isDefaultExpandAll: true,
    fileTree: []
}

const actions: IFileListActions = {

}

const mutations: IFileListMutations = {
    async _getFileTree(state: IFileListState) {
        const fileTree = await getFileTree();
        if (fileTree) {
            state.fileTree = fileTree;
            setLocalStorage('fileTree', fileTree);
        }
    },
    _setFileTree(state: IFileListState, fileTree: any[]) {
        state.fileTree = fileTree;
    },

}
const getters: IFileListGetter = {
    getFileTree: (state: IFileListState) => state.fileTree,
}

export const fileList: Module<IFileListState, RootState> = {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}
